package com.zsrt.java.ex;


import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.Test;

public class TypeTest {
	
	@Test
	public void zidong() throws Exception {
	/*	//自动装箱
		Integer i=100;
		//自动拆箱
		int j=i;*/
		
		Integer i=new Integer(100);
		Double d=new Double("123.456");
		
		int j=i+d.intValue();
		
		float f=i.floatValue()+d.floatValue();
		System.out.println(j);
		System.out.println(f);
		
		double p1=Double.parseDouble("3.14");
		double r=2.0;
		double s=p1*r*r;
		System.out.println(s);
		
		System.out.println("=================================");
		
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM--dd--hh-mm-ss");
		
		String formatdate=sdf.format(new Date());
		System.out.println(formatdate);
		
	
	}
	
	/**
	 * 看不懂
	 * 
	 * @throws Exception
	 */
	@Test
	public void timeFormatTest() throws Exception {
		
		String str="2017-01-01";
		
		try {
			DateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
			Date date=sdf.parse(str);
			System.out.println(date.getTime());
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	

	@Test
	public void Calendar() throws Exception {
		
		Calendar c=Calendar.getInstance();
		
		Date date=c.getTime();
		int i = c.get(Calendar.DAY_OF_WEEK);
		System.out.println("今天是星期"+(i-1));
		c.set(Calendar.YEAR,2030);
		c.set(Calendar.MONTH, 0);
		c.set(Calendar.DATE,1);
		System.out.println(c.getTime());
		
	}
	
	
	@Test
	public void NumberFormatTest() throws Exception {
		
		NumberFormat nformat=NumberFormat.getNumberInstance();
		nformat.setMinimumIntegerDigits(3);
		nformat.setMinimumFractionDigits(5);
		System.out.println(nformat.format(Math.PI));
		
		NumberFormat cFormat=NumberFormat.getCurrencyInstance();
		cFormat.setMaximumFractionDigits(3);
		System.out.println(cFormat.format(Math.PI));
		
		
		NumberFormat pformat=NumberFormat.getPercentInstance();
		pformat.setMaximumFractionDigits(4);
		System.out.println(pformat.format(Math.PI));
		
	}
	
	@Test
	public void MathTest() throws Exception {
		
		int a=Math.abs(-123);
		System.out.println(a);
		
		double c=Math.sqrt(2);
		System.out.println(c);
		
		for(int i=0;i<100;i++){
			System.out.println(new Random().nextBoolean());
			System.out.println(new Random().nextFloat());
			System.out.println(new Random().nextLong());
			System.out.println(new Random().nextInt());
			System.out.println(new Random().nextDouble());
			System.out.println(new Random().nextInt());
		}
	}
	
	
	@Test
	public void Pattern() throws Exception {
		String regexrules="^abc";
		String matchstr="ab";
		Pattern pattern=Pattern.compile(regexrules);
		
		//Matcher是正则表达式的匹配器，
		//通过匹配器把编译好的则正表达式与指定的字符串进行匹配
		
		Matcher matcher=pattern.matcher(matchstr);
		boolean b=matcher.matches();
		System.out.println(b);
		
	}
	
	@Test
	public void BigDecimal() throws Exception {
		
		double i=1.1;
		double j=0.5;
		System.out.println(i-j);
		
		BigDecimal a=new BigDecimal(1.1);
		BigDecimal b=new BigDecimal(0.5);
		BigDecimal bigResult=new BigDecimal(0);
//		bigResult = a.multiply(b);
		bigResult=a.add(b);
		System.out.println(bigResult.toString());
		System.out.println(bigResult.doubleValue());
		
		
	}
	

}
